package com.gome.oa.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author: tang li
 * @date: 2016年8月13日
 * @desc: 
 *
 */
public class DateUtil {
	
	public static String format(Date date) {
		return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(date);
	}
	
	public static Date parse(String str) throws ParseException {
		return new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(str);
	}
	
	public static String format1(Date date) {
		return new SimpleDateFormat("yyyy-MM-dd").format(date);
	}
	
	public static String format2(Date date) {
		return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
	}
	
	public static String format3(Date date) {
		if(date == null) {
			return "";
		}
		return new SimpleDateFormat("HH:mm").format(date);
	}
	
	public static Date getLastMonthFirstDay() {
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.MONTH, -1);
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		return calendar.getTime();
	}
	
	public static Date getLastMonthLastDay() {
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.DAY_OF_MONTH,0);
		return calendar.getTime();
	}
	
	public static String getCurrentDay() {
		return format1(new Date());
	}
	
	public static boolean isDate(String str) {
		if(str == null || str.length() != 10) {
			return false;
		}
		try {
			new SimpleDateFormat("yyyy-MM-dd").parse(str);
			return true;
		} catch (ParseException e) {
		}
		return false;
	}

}
